package t4;

import java.util.Calendar;

import t4bean.CustomerBean;
import t4bean.SalesvolumDateBean;
import t4bean.SalesvolumeRecordBean;
import t4bean.StallBean;
import t4bean.StockBean;

/**
 * 卖水果逻辑 女性打折
 *
 */
public class SellFruit {
	/**直接将折扣存入SalesvolimeRecord中便于后期计算
	 * 将售货日期存入SalesvolimDate中
	 * 判断时候17：00后
	 */
	public StallBean sellFruit(CustomerBean customer, StallBean stall, String fruitName, Integer volume) {
		for (StockBean stock : stall.getStockList()) {
			if (stock.getFruit().getName().equals(fruitName) && stock.getStockNumber() >= volume) {
				if (customer.getSex() == 0) {
					SalesvolumeRecordBean svr = new SalesvolumeRecordBean(stock.getFruit(), volume, 8);
					Calendar cal = Calendar.getInstance();
					SalesvolumDateBean sd = new SalesvolumDateBean(stock.getFruit(), svr, cal.get(Calendar.MONTH),
							cal.get(Calendar.DAY_OF_MONTH)+1);
					stall.getSalDateList().add(sd);
					stall.getSalList().add(svr);
					stock.setStockNumber(stock.getStockNumber() - volume);
				} else {
					SalesvolumeRecordBean svr = new SalesvolumeRecordBean(stock.getFruit(), volume, 10);
					stall.getSalList().add(svr);
					Calendar cal = Calendar.getInstance();
					SalesvolumDateBean sd = new SalesvolumDateBean(stock.getFruit(), svr, cal.get(Calendar.MONTH),
							cal.get(Calendar.DAY_OF_MONTH));
					stall.getSalDateList().add(sd);
					stock.setStockNumber(stock.getStockNumber() - volume);
				}

			}
		}
		return stall;

	}

	public StallBean sellFruitAfterFive(CustomerBean customer, StallBean stall, String fruitName, Integer volume) {
		for (StockBean stock : stall.getStockList()) {
			if (stock.getFruit().getName().equals(fruitName) && stock.getStockNumber() >= volume) {
				if (customer.getSex() == 0) {
					SalesvolumeRecordBean svr = new SalesvolumeRecordBean(stock.getFruit(), volume, 4);
					stall.getSalList().add(svr);
					Calendar cal = Calendar.getInstance();
					SalesvolumDateBean sd = new SalesvolumDateBean(stock.getFruit(), svr, cal.get(Calendar.MONTH),
							cal.get(Calendar.DAY_OF_MONTH));
					stall.getSalDateList().add(sd);
					stock.setStockNumber(stock.getStockNumber() - volume);
				} else {
					SalesvolumeRecordBean svr = new SalesvolumeRecordBean(stock.getFruit(), volume, 5);
					stall.getSalList().add(svr);
					Calendar cal = Calendar.getInstance();
					SalesvolumDateBean sd = new SalesvolumDateBean(stock.getFruit(), svr, cal.get(Calendar.MONTH),
							cal.get(Calendar.DAY_OF_MONTH));
					stall.getSalDateList().add(sd);
					stock.setStockNumber(stock.getStockNumber() - volume);
				}

			}
		}
		return stall;
	}
}
